import 'package:flutter/material.dart';

// ignore: must_be_immutable
class MyTapWidget extends StatelessWidget {
  ///防止重复点击
  static const int clickTime = 200;

  final Widget child;
  final GestureTapCallback onTap;
  final GestureLongPressCallback? onLongPress;
  int lastClickTime = 0;

  MyTapWidget({super.key, required this.child, required this.onTap, this.onLongPress});

  @override
  Widget build(BuildContext context) {

    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        var dateTimeNowMilli = DateTime.now().millisecondsSinceEpoch;
        if (dateTimeNowMilli - lastClickTime > clickTime) {
          lastClickTime = dateTimeNowMilli;
          onTap.call();
        }
      },
      onLongPress: onLongPress,
      child: child,
    );
  }
}
